export default class Request {
    http(param) {
        let url = param.url;
        let method = param.method;
        let header = param.header || {};
        let data = Object.assign(param.data || {});
        let hideLoading = param.hideLoading || false;
        // 第一步的代码均在此处展示，后面示例代码就不写外层 class 和 http方法了。
        
		let requestUrl = 'http://192.168.36.46:3000/' + url;
		if (method) {
		    if (method == "POST") {
		        header = Object.assign({
		            'content-type': "application/x-www-form-urlencoded"
		        }, param.header)
		    } else {
		        header = Object.assign({
		            'content-type': "application/json"
		        }, param.header)
		    }
		}
		if (!hideLoading) {
		    uni.showLoading()
		}
		return new Promise((resolve, reject) => {
		    uni.request({
		        url: requestUrl,
		        data: data,
		        method: method,
		        header: header,
		        success: (res) => {
		            // 下面会直接写请求成功的代码
		            console.log(成功);
		        },
		        fail: (err) => {
		            // 下面会直接写请求失败的代码
					console.log(失败);
		        },
		    })
		})
		
    }
}
